<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="账户编号" prop="userId">
      <el-input v-model="dataForm.userId" placeholder="账户编号"></el-input>
    </el-form-item>
    <el-form-item label="姓名" prop="extraName">
      <el-input v-model="dataForm.extraName" placeholder="姓名"></el-input>
    </el-form-item>
    <el-form-item label="性别" prop="male">
      <el-input v-model="dataForm.male" placeholder="性别"></el-input>
    </el-form-item>
    <el-form-item label="身份证号" prop="id">
      <el-input v-model="dataForm.id" placeholder="身份证号"></el-input>
    </el-form-item>
    <el-form-item label="手机号" prop="mobile">
      <el-input v-model="dataForm.mobile" placeholder="手机号"></el-input>
    </el-form-item>
    <el-form-item label="微信号" prop="wechatId">
      <el-input v-model="dataForm.wechatId" placeholder="微信号"></el-input>
    </el-form-item>
    <el-form-item label="身份证正面图片地址" prop="idImageA">
      <el-input v-model="dataForm.idImageA" placeholder="身份证正面图片地址"></el-input>
    </el-form-item>
    <el-form-item label="身份证背面图片地址" prop="idImageB">
      <el-input v-model="dataForm.idImageB" placeholder="身份证背面图片地址"></el-input>
    </el-form-item>
    <el-form-item label="开户行" prop="bank">
      <el-input v-model="dataForm.bank" placeholder="开户行"></el-input>
    </el-form-item>
    <el-form-item label="银行卡号" prop="cardNum">
      <el-input v-model="dataForm.cardNum" placeholder="银行卡号"></el-input>
    </el-form-item>
    <el-form-item label="人员信息审核状态" prop="auditStatus">
      <el-input v-model="dataForm.auditStatus" placeholder="人员信息审核状态"></el-input>
    </el-form-item>
    <el-form-item label="创建时间" prop="createTime">
      <el-input v-model="dataForm.createTime" placeholder="创建时间"></el-input>
    </el-form-item>
    <el-form-item label="更新时间" prop="updateTime">
      <el-input v-model="dataForm.updateTime" placeholder="更新时间"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          userExtraId: 0,
          userId: '',
          extraName: '',
          male: '',
          id: '',
          mobile: '',
          wechatId: '',
          idImageA: '',
          idImageB: '',
          bank: '',
          cardNum: '',
          auditStatus: '',
          createTime: '',
          updateTime: ''
        },
        dataRule: {
          userId: [
            { required: true, message: '账户编号不能为空', trigger: 'blur' }
          ],
          extraName: [
            { required: true, message: '姓名不能为空', trigger: 'blur' }
          ],
          male: [
            { required: true, message: '性别不能为空', trigger: 'blur' }
          ],
          id: [
            { required: true, message: '身份证号不能为空', trigger: 'blur' }
          ],
          mobile: [
            { required: true, message: '手机号不能为空', trigger: 'blur' }
          ],
          wechatId: [
            { required: true, message: '微信号不能为空', trigger: 'blur' }
          ],
          idImageA: [
            { required: true, message: '身份证正面图片地址不能为空', trigger: 'blur' }
          ],
          idImageB: [
            { required: true, message: '身份证背面图片地址不能为空', trigger: 'blur' }
          ],
          bank: [
            { required: true, message: '开户行不能为空', trigger: 'blur' }
          ],
          cardNum: [
            { required: true, message: '银行卡号不能为空', trigger: 'blur' }
          ],
          auditStatus: [
            { required: true, message: '人员信息审核状态不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ],
          updateTime: [
            { required: true, message: '更新时间不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.userExtraId = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.userExtraId) {
            this.$http({
              url: this.$http.adornUrl(`/quickService/userextra/info/${this.dataForm.userExtraId}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.userId = data.userextra.userId
                this.dataForm.extraName = data.userextra.extraName
                this.dataForm.male = data.userextra.male
                this.dataForm.id = data.userextra.id
                this.dataForm.mobile = data.userextra.mobile
                this.dataForm.wechatId = data.userextra.wechatId
                this.dataForm.idImageA = data.userextra.idImageA
                this.dataForm.idImageB = data.userextra.idImageB
                this.dataForm.bank = data.userextra.bank
                this.dataForm.cardNum = data.userextra.cardNum
                this.dataForm.auditStatus = data.userextra.auditStatus
                this.dataForm.createTime = data.userextra.createTime
                this.dataForm.updateTime = data.userextra.updateTime
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/quickService/userextra/${!this.dataForm.userExtraId ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'userExtraId': this.dataForm.userExtraId || undefined,
                'userId': this.dataForm.userId,
                'extraName': this.dataForm.extraName,
                'male': this.dataForm.male,
                'id': this.dataForm.id,
                'mobile': this.dataForm.mobile,
                'wechatId': this.dataForm.wechatId,
                'idImageA': this.dataForm.idImageA,
                'idImageB': this.dataForm.idImageB,
                'bank': this.dataForm.bank,
                'cardNum': this.dataForm.cardNum,
                'auditStatus': this.dataForm.auditStatus,
                'createTime': this.dataForm.createTime,
                'updateTime': this.dataForm.updateTime
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
